/*
 Copyright (C) 2009 QDSS.org
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.qdss.persist.engine;

import java.io.Serializable;


import org.apache.commons.lang.StringUtils;
import org.qdss.persist.util.UUIDHexGenerator;

/**
 * ID生成器
 * 
 * @author <a href="mailto:devezhao@126.com">FANGFANG ZHAO</a>
 * @since 0.1, 06/13/08
 * @version $Id: IDGenerator.java 119 2011-05-15 16:56:18Z zhaofang123@gmail.com $
 */
public class IDGenerator extends UUIDHexGenerator {

	static char SEP = '-';

	public IDGenerator() {
		super(SEP);
	}

	/**
	 * ENTITY_CODE - IP - JVM - MO_TIME - LO_TIME - COUNT
	 * 
	 * @param entityCode
	 * @return
	 */
	public Serializable generate(Integer entityCode) {
		return new StringBuilder(getLength()).append(
				StringUtils.leftPad(entityCode + "", 3, '0')).append(SEP)
				.append(super.generate());
	}
	
	@Override
	public Serializable generate() {
		return generate(0);
	}
	
	@Override
	public int getLength() {
		return 40;
	}
}
